package com.oc.mba.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.oc.mba.entity.OcBackendUser;

public class BaseBackendController extends MultiActionController {
	
	public boolean hasSession(HttpServletRequest httpRequest,
            HttpServletResponse httpResponse) {
		HttpSession session = httpRequest.getSession(true);
		if (session.getAttribute("SESSTIONUSER") == null) {
			return false;
		}
		return true;
	}
	
	public void setSession(OcBackendUser user, HttpServletRequest httpRequest,
            HttpServletResponse httpResponse) {
		HttpSession session = httpRequest.getSession(true);
		Map<String, String> sessionMap = new HashMap<String, String>();
		sessionMap.put("userID", String.valueOf(user.getId()));
		sessionMap.put("userName", user.getAdminName());
		session.setAttribute("SESSTIONUSER", sessionMap);
	}
	
	public void removeSession(HttpServletRequest httpRequest,
			HttpServletResponse httpResponse) {
		HttpSession session = httpRequest.getSession(true);
		session.removeAttribute("SESSTIONUSER");
	}
	
}
